#include <iostream>
using namespace std;

//删除单向链表倒数第k个节点
class ListNode
{
public:
    ListNode(int val) {
        this->val = val;
        this->next = NULL;
    }
    int val;
    ListNode * next;
};

ListNode* getAns(ListNode* root, int k) {
    ListNode* dummy = new ListNode(-1); //注意！不然删第一个会有问题
    dummy->next = root;
    ListNode* fast = dummy;
    ListNode* slow = dummy;
    k++;
    while (k--) {
        fast = fast->next;
    }
    while (fast) {
        fast = fast->next;
        slow = slow->next;
    }
    slow->next = slow->next->next;
    return dummy->next;
}

int main() {
    ListNode* root = new ListNode(1);
    root->next = new ListNode(2);
    root->next->next = new ListNode(3);
    ListNode* tmp = getAns(root, 3);
    while (tmp) {
        cout << tmp->val << "->";
        tmp = tmp->next;
    }
}
